<#
This isused to connect rdc sessions
#>
$vm_server=@{
	"NAM-PROD-1"="ICGSWAPP2N01";
	"NAM-PROD-2"="ICGSWAPP2N02";
	"NAM-PROD-3"="ICGSWAPP2N03";
	"NAM-PROD-4"="ICGSWDBP2N01";
	"NAM-UAT-1"="ICGSWAPU2N01";
	"NAM-UAT-2"="ICGSWAPU2N02";
	"NAM-UAT-3"="ICGSWAPU2N03";
	"NAM-UAT-4"="ICGSWDBU2N01";
	"NAM-DEV-1"="SD-D19B-F249";
	"NAM-DEV-2"="vm-3178-18b8";
	"NAM-DEV-3"="SD-9005-AA72";
	"NAM-DEV-4"="SD-A433-5026";
	"NAM-POC-1"="SD-4952-44E2";
	"NAM-POC-2"="vm-76f7-970e";
	"NAM-POC-3"="SD-72F6-C227";
	"NAM-POC-4"="SD-72F6-C227";
	"APAC-PROD-1"="ICGSGAPP2N01";
	"APAC-PROD-2"="ICGSGAPP2N02";
	"APAC-PROD-3"="ICGSGAPP2N03";
	"APAC-PROD-4"="ICGSGDBP2N01";
	"APAC-UAT-1"="ICGHKAPU2N01";
	"APAC-UAT-2"="ICGHKAPU2N02";
	"APAC-UAT-3"="ICGHKAPU2N03";
	"APAC-UAT-4"="ICGHKDBU2N01";
	"EMEA-PROD-1"="ICGRDAPP2N01";
	"EMEA-PROD-2"="ICGRDAPP2N02";
	"EMEA-PROD-3"="ICGRDAPP2N03";
	"EMEA-PROD-4"="ICGRDDBP2N01";
	"EMEA-UAT-1"="ICGFFAPU2N01";
	"EMEA-UAT-2"="ICGFFAPU2N02";
	"EMEA-UAT-3"="ICGFFAPU2N03";
	"EMEA-UAT-4"="ICGFFDBU2N01"
}
Function Connect-RDC(){
	param(
		[Parameter(Mandatory=$True)]
		[string]$vdi,
		[string]$fid,
		[string]$passwd
	)
	cmdkey.exe /generic:$vdi /user:$fid /pass:$passwd 1>$null
	If($vdi -in $vm_server.Values ){
	    mstsc.exe /v $vdi
	}else{
	    mstsc.exe /v $vdi /w 1376 /h 768
	}
}
#<----------------------------------------------1 initilize Assembles
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")  
#<----------------------------------------------2 create the main form
$form = New-Object System.Windows.Forms.Form 
$form.Text = "Connect To Remote Computer"
$Font = New-Object System.Drawing.Font("Times New Roman",12,[System.Drawing.FontStyle]::Regular) # Regular, Bold, Italic, Underline, Strikeout
$Form.Font = $Font
$form.Size = New-Object System.Drawing.Size(380,350)
$form.FormBorderStyle = 'FixedSingle'
$form.StartPosition = "CenterScreen"
$form.AutoSizeMode = 'GrowAndShrink'
#<----------------------------------------------3 Create the Label.
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Size(10,10) 
$label.Size = New-Object System.Drawing.Size(280,20)
$label.AutoSize = $true
$label.Text = "Please select domain,env,node to connect."
$form.Controls.Add($label)
#<----------------------------------------------4 Create the domain dropbox.
$DomainDropDownBox = New-Object System.Windows.Forms.ComboBox
$DomainDropDownBox.Location = New-Object System.Drawing.Size(20,35) 
$DomainDropDownBox.Size = New-Object System.Drawing.Size(80,20) 
$DomainDropDownBox.DropDownHeight = 200 
'APAC','EMEA','NAM'|%{$DomainDropDownBox.Items.Add($_) 1>$NULL}
$DomainDropDownBox.SelectedIndex=2
$Form.Controls.Add($DomainDropDownBox) 
#<----------------------------------------------5 Create the env dropbox.
$EnvDropDownBox = New-Object System.Windows.Forms.ComboBox
$EnvDropDownBox.Location = New-Object System.Drawing.Size(120,35) 
$EnvDropDownBox.Size = New-Object System.Drawing.Size(80,20) 
$EnvDropDownBox.DropDownHeight = 200 
'PROD','UAT','DEV','POC'|%{$EnvDropDownBox.Items.Add($_) 1>$NULL}
$EnvDropDownBox.SelectedIndex=0
$Form.Controls.Add($EnvDropDownBox) 
#<----------------------------------------------6 Create the node dropbox.
$NodeDropDownBox = New-Object System.Windows.Forms.ComboBox
$NodeDropDownBox.Location = New-Object System.Drawing.Size(220,35) 
$NodeDropDownBox.Size = New-Object System.Drawing.Size(80,20) 
$NodeDropDownBox.DropDownHeight = 200 
'1','2','3','4'|%{$NodeDropDownBox.Items.Add($_) 1>$NULL}
$NodeDropDownBox.SelectedIndex=0
$Form.Controls.Add($NodeDropDownBox) 
#<----------------------------------------------7 Create the Label.
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Size(10,70) 
$label.Size = New-Object System.Drawing.Size(280,20)
$label.AutoSize = $true
$label.Text = "Or Enter bellow info to connect.`nIf password is empty, it will use the default password.`nIf fid is aaadmin, then password can be empty."
$form.Controls.Add($label)
#<----------------------------------------------8 Create the TextBox used to capture the vdi
$vdi_label= New-Object System.Windows.Forms.Label
$vdi_label.Location = New-Object System.Drawing.Size(5,130) 
$vdi_label.Size = New-Object System.Drawing.Size(20,20)
$vdi_label.AutoSize = $true
$vdi_label.Text = "VDI: "
$form.Controls.Add($vdi_label)
$VDITextBox = New-Object System.Windows.Forms.TextBox 
$VDITextBox.Location = New-Object System.Drawing.Size(55,130) 
$VDITextBox.Size = New-Object System.Drawing.Size(300,20)
$VDITextBox.AcceptsReturn = $true
$VDITextBox.AcceptsTab = $false
$form.Controls.Add($VDITextBox)
#<----------------------------------------------9 Create the TextBox used to capture the fid
$fid_label= New-Object System.Windows.Forms.Label
$fid_label.Location = New-Object System.Drawing.Size(5,170) 
$fid_label.Size = New-Object System.Drawing.Size(20,20)
$fid_label.AutoSize = $true
$fid_label.Text = "FID: "
$form.Controls.Add($fid_label)
$FIDTextBox = New-Object System.Windows.Forms.TextBox 
$FIDTextBox.Location = New-Object System.Drawing.Size(55,170) 
$FIDTextBox.Size = New-Object System.Drawing.Size(300,20)
$FIDTextBox.AcceptsReturn = $true
$FIDTextBox.AcceptsTab = $false
$FIDTextBox.Text = "aaadmin"
$form.Controls.Add($FIDTextBox)
#<----------------------------------------------10 Create the TextBox used to capture password
$pwd_label= New-Object System.Windows.Forms.Label
$pwd_label.Location = New-Object System.Drawing.Size(5,210) 
$pwd_label.Size = New-Object System.Drawing.Size(20,20)
$pwd_label.AutoSize = $true
$pwd_label.Text = "PWD: "
$form.Controls.Add($pwd_label)
$PWDTextBox = New-Object System.Windows.Forms.TextBox
$PWDTextBox.Location = New-Object System.Drawing.Size(55,210) 
$PWDTextBox.Size = New-Object System.Drawing.Size(300,20)
$PWDTextBox.PasswordChar = '*'
$form.Controls.Add($PWDTextBox)
#<----------------------------------------------11 Create the connect button.
$ConnectButton= New-Object System.Windows.Forms.Button
$ConnectButton.Location = New-Object System.Drawing.Size(20,260)
$ConnectButton.Size = New-Object System.Drawing.Size(80,25)
$ConnectButton.Text = "Connect"
$ConnectButton.Add_Click({ 
	$domain= $DomainDropDownBox.SelectedItem.ToString()
	$env   = $EnvDropDownBox.SelectedItem.ToString()
	$node  = $NodeDropDownBox.SelectedItem.ToString()
	$vdi=$VDITextBox.Text
	If( ![string]::IsNullOrWhiteSpace($vdi) ){
		$fid=$FIDTextBox.Text
		$password=$PWDTextBox.Text
		If( $fid -eq 'aaadmin'){
		    $fid,$password='nam\aaadmin','xxxxxx'
		}
		If( $fid -inotmatch 'aaadmin' ){If([string]::IsNullOrWhiteSpace($password ) ){$password='RTest123'}}
	}else{
		$vdi=$vm_server."$domain-$env-$node"
		If( $env -ieq 'prod' ){$fid,$password='nam\aaadmin_p','xxxxxx'
		}else{$fid,$password='nam\aaadmin','xxxxxx'}
	}
	Connect-RDC $vdi $fid $password
})
$Form.Controls.Add($ConnectButton) 
#<----------------------------------------------12 Create the clear button.
$ClearText = New-Object System.Windows.Forms.Button
$ClearText.Location = New-Object System.Drawing.Size(120,260)
$ClearText.Size = New-Object System.Drawing.Size(80,25)
$ClearText.Text = "Clear"
$ClearText.Add_Click({ $VDITextBox.Text = $null ; $FIDTextBox.Text=$null ; $PWDTextBox.Text=$null})
$Form.Controls.Add($ClearText) 
#<----------------------------------------------13 Create the Quit button.
$QuitButton = New-Object System.Windows.Forms.Button
$QuitButton.Location = New-Object System.Drawing.Size(220,260)
$QuitButton.Size = New-Object System.Drawing.Size(80,25)
$QuitButton.Text = "Quit"
$QuitButton.Add_Click({$form.Close()})
$Form.Controls.Add($QuitButton) 
#<----------------------------------------------14 initilize form and show it
$Form.ShowInTaskbar = $true
$Form.Add_Shown({$form.Activate()})
$Form.ShowDialog() > $null

